<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="用户名">
        <el-input v-model="form.username"></el-input>
      </el-form-item>

      <el-form-item label="密码">
        <el-button type="warning" plain @click="checkpwd" v-model="form.password">修改密码</el-button>
      </el-form-item>

      <el-form-item label="昵称">
        <el-input v-model="form.nickname"></el-input>
      </el-form-item>

      <el-form-item label="上级">
        {{this.form.pname}}
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">修改</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>




    <el-dialog title="修改密码" :visible.sync="showformpw" width="80%">
      <el-form :model="formpw">
        <el-form-item label="原密码">
          <el-input v-model="formpw.oldpw" type="password" placeholder="原密码" auto-complete="off"></el-input>
        </el-form-item>

        <el-form-item label="新密码">
          <el-input v-model="formpw.password" type="password" placeholder="新密码" auto-complete="off"></el-input>
        </el-form-item>

        <el-form-item label="新密码确认">
          <el-input v-model="formpw.repassword" type="password" placeholder="新密码确认" auto-complete="off"></el-input>
        </el-form-item>


        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="showformpw = false">取 消</el-button>
        <el-button type="primary" @click="postnewpwd">确 定</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { mapGetters } from "vuex";

export default {
  computed: {
    ...mapGetters(["userInfo"])
  },
  data() {
    return {
      form: {
        username: "", //this.userInfo.username,
        password: "",
        nickname: "", //this.userInfo.nickname,
        pname: "" //this.userInfo.pname
      },
      formpw: {
        oldpw: "",
        password: "",
        repassword: ""
      },
      showformpw: false
    };
  },
  methods: {
    onSubmit() {
      this.$message("submit!");
    },
    onCancel() {
      this.$message({
        message: "cancel!",
        type: "warning"
      });
    },
    checkpwd() {
      this.showformpw = true;
    },
    postnewpwd() {
      this.$store
        .dispatch("Pwdchange", this.formpw)
        .then(response => {
          //console.log(response);
          this.showformpw = false;
        })
        .catch(err => {
          console.log(err);
        });
    }
  },
  mounted() {
    this.form = this.userInfo;
    console.log(this.userInfo);
  }
};
</script>

<style scoped>
.line {
  text-align: center;
}
</style>

